//
//  LabelAndCollectionReusableView.m
//  14-collectionview-test
//
//  Created by Snow on 16/8/2.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "LabelAndCollectionReusableView.h"
#define kCollection @"collection"
@interface LabelAndCollectionReusableView ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UILabel *label;
@end
@implementation LabelAndCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 50)];
        [self addSubview:_label];
        _label.text = @"分类";
        UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
        CGFloat height = CGRectGetHeight(frame) - 50 - 40;
        flow.itemSize = CGSizeMake((frame.size.width - 30) / 2 , height / 3);
        flow.minimumLineSpacing = 10;
        flow.minimumInteritemSpacing = 0;
        flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        flow.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, frame.size.width, frame.size.height - 50) collectionViewLayout:flow];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [self addSubview:_collectionView];
        _collectionView.pagingEnabled = YES;
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCollection];
    }
    return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 12;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollection forIndexPath:indexPath];
    cell.backgroundColor = [UIColor cyanColor];
    return cell;
}
@end
